package demo;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author tongchen
 * @create 2022-11-28 19:18
 */
@WebServlet("/demo3")
public class ServletDemo2 implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
       //创建http servlet属性
        HttpServletRequest request=(HttpServletRequest) servletRequest;
        String method=request.getMethod();
        //测试method类型
        if("GET".equals(method)){
            getMethod(servletRequest,servletResponse);
        }else{
            postMethod(servletRequest,servletResponse);
        }
    }

    protected void postMethod(ServletRequest servletRequest, ServletResponse servletResponse) {
    }

    protected void getMethod(ServletRequest servletRequest, ServletResponse servletResponse) {
        
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
